package com.wc.codeforces.模拟.Preparing_for_the_Exam;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/1/3 14:57
 * @description
 * https://codeforces.com/contest/2051/problem/C
 */
public class Main {
    /**
     * 思路：
     * 观察出, 他就不出一个题, 那说明如果有多余两个题不会, 那就全是0
     * 如果全会, 那全是1
     * 如果说就一个不会, 处理那个不出的是1, 全是0
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 300010;
    static int[] a = new int[N], q = new int[N];
    static int n, m, k;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            m = sc.nextInt();
            k = sc.nextInt();
            for (int i = 1; i <= m; i++) a[i] = sc.nextInt();
            for (int i = 1; i <= k; i++) q[i] = sc.nextInt();
            if (n - k >= 2) for (int i = 1; i <= m; i++) out.print(0);
            else if (n - k == 0) for (int i = 1; i <= m; i++) out.print(1);
            else {
                int pass = k + 1;
                for (int i = 1; i <= k; i++) {
                    if (i != q[i]) {
                        pass = i;
                        break;
                    }
                }
                for (int i = 1; i <= m; i++) {
                    if (a[i] == pass) out.print(1);
                    else out.print(0);
                }
            }

            out.println();
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

